﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Prototype1.UtilControls
{
    public partial class RichCalendar : System.Web.UI.UserControl
    {
        private static string[] months = new string[] { "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" };

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            for (int i = 1 /* já temos o janeiro no aspx */;
                i < months.Length;
                i++)
            {
                ddlMonth.Items.Add(new ListItem(months[i], (i + 1).ToString()));
            }

            btnChangeDate.Click += new EventHandler(btnChangeDate_Click);
            calendar.SelectionChanged += new EventHandler(calendar_SelectionChanged);
        }

        public DateTime SelectedDate
        {
            get
            {
                return this.calendar.SelectedDate;
            }
            set
            {
                this.calendar.SelectedDate = value;
            }
        }

        void calendar_SelectionChanged(object sender, EventArgs e)
        {
            txtYear.Text = calendar.SelectedDate.Year.ToString();
            ddlMonth.SelectedIndex = calendar.SelectedDate.Month;
        }

        void btnChangeDate_Click(object sender, EventArgs e)
        {
            int year = int.Parse(txtYear.Text);
            int month = int.Parse(ddlMonth.SelectedValue);
            int day = calendar.SelectedDate.Day;
            calendar.SelectedDate =
                calendar.VisibleDate =
                new DateTime(year, month, day);
        }

    }
}